﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#define HEADER_PROPERTY_NAME "Header"

// Qt headers
#include <QWidget>
#include <QMap>


class QHBoxLayout;
class QStackedLayout;
class QFrame;
class QLabel;

namespace gmepgcs
{
    class CustomTab : public QWidget
    {
        Q_OBJECT
    public:
        explicit CustomTab(QWidget *parent = nullptr);
        virtual ~CustomTab();

        void AddTabItem(QString header, QWidget *bodyWidget);
        void SetTabItemVisible(QString header, bool visible);

        Qt::Alignment HeaderAlignment();
        void SetHeaderAlignment(Qt::Alignment alignment);

        void SetStandAloneHeaderVisible(bool visible);

        void SetHeaderBackgorund(QColor &bgColor);

        void SetHeaderVisible(bool visible);

        QWidget* GetCurrentHeaderWidget();
        QWidget* GetWidgetAt(int index);
    public:
        enum HeaderStyleFlag
        {
            Normal = 0x00000000,
            Current = 0x00000001,
            First = 0x00000002,
            Middle = 0x00000004,
            Last = 0x00000008,
            StandAlone = 0x00000010
        };
    public:
        void SetShowSplitterLine(bool show);
        QString CurrentTab();

    signals:
        void CurrentTabChanged(QString currentTabHeader);

    public slots:
        void SwtichToTab(QWidget *headerWidget);    

    protected:
        virtual QWidget *CreateHeaderWidget(QString header) = 0;
        virtual void UpdateHeaderWidget(QWidget *headerWidget, int headerStyleFlag = HeaderStyleFlag::Normal) = 0; 
        virtual void showEvent(QShowEvent *event) override;

    private:
        void Init();
        void UpdateHeaderWidgets();

    private:
        QHBoxLayout *m_pHeaderLayout;
        QList<QWidget*> m_lstHeaderWidgets;

        QStackedLayout *m_pBodyLayout;
        QHash<QWidget *, QWidget *> m_hsTabItems;

        QFrame *m_pHeaderPanelFrame;

        Qt::Alignment m_headerAlignment;
        QWidget *m_pCurrentHeaderWidget;

        bool m_standAloneHeaderVisible;
        QLabel *m_pSplitterLine;
    };
}